<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true">
      <el-form-item label="联系人姓名" prop="keyword">
        <el-input v-model="queryParams.keyword" placeholder="请输入姓名/联系方式" clearable size="small" />
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['gongyuan:supervision:add']">新增</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="list">
      <el-table-column label="登录名" prop="userName" :show-overflow-tooltip="true" />
      <el-table-column label="姓名"  prop="nickName"  :show-overflow-tooltip="true" />
      <el-table-column label="联系方式" prop="phonenumber" :show-overflow-tooltip="true" />
      <el-table-column label="提成比例" :formatter="rateFormat"  :show-overflow-tooltip="true" />
      <el-table-column label="是否禁用" :formatter="stateFormat"  :show-overflow-tooltip="true" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-view" @click="handleDetail(scope.row)" v-hasPermi="['gongyuan:supervision:findbyid']">查看</el-button>
          <el-button class="gongyuan-update" size="mini" type="text" icon="el-icon-edit" @click="handleEdit(scope.row)" v-hasPermi="['gongyuan:supervision:edit']">修改</el-button>
          <el-button class="gongyuan-disabled" v-if="scope.row.status=='0'" size="mini" type="text" icon="el-icon-remove" @click="handleDelete(scope.row,1)" v-hasPermi="['gongyuan:supervision:disable']">禁用</el-button>
          <el-button v-if="scope.row.status=='1'" size="mini" type="text" icon="el-icon-check" @click="handleDelete(scope.row,0)" v-hasPermi="['gongyuan:supervision:disable']">启用</el-button>
          <el-button size="mini" class="gongyuan-delete" type="text" icon="el-icon-delete" @click="handleDeleteData(scope.row)" v-hasPermi="['gongyuan:supervision:disable']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />

  </div>
</template>

<script>
  import { getAgentList,removeAgent,delAgent } from '@/api/agent/agent'
  export default {
    name: "Agentlist",
    data() {
      return {
        // 遮罩层
        loading: true,
        list: [],
        total: 0,
        // 查询参数
        queryParams: {
          keyword: '',
          pageNum: 1,
          pageSize: 10
        }
      }
    },
    created() {
      this.getList()
    },
    methods:{
      async getList() {
        this.loading = true
        const res = await getAgentList(this.queryParams)
        this.list = res.rows
        this.total = res.total
        this.loading = false
      },
      stateFormat(row, column) {
        if (row.status === "0") {
          return '否'
        } else  {
          return '是'
        }
      },rateFormat(row, column){
        return row.rate+"%"
      },
      handleAdd() {
        // 此处后台管理添加的路由, path对应组件name须一致,不可再修改
        this.$router.push({ name: 'Agentedit' })
      },
      handleEdit(row) {
        this.$router.push({ name: 'Agentedit', query: { id: row.id } })
      },
      handleDetail(row){
        this.$router.push({ name: 'Agentdetail', query: { id: row.id } })
      },
      handleDeleteData(row){
        const superId=row.id
        this.$confirm('是否确认删除中介用户编号为"' + superId + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return removeAgent(superId);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
      },
      handleDelete(row,status){
        const superId=row.id
        this.$confirm('是否确认操作中介用户编号为"' + superId + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delAgent({id:superId,status:status});
        }).then(() => {
          this.queryParams.pageNum = 1
          this.getList();
          this.msgSuccess("操作成功");
        }).catch(function() {});
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm('queryForm')
        this.handleQuery()
      }
    }
  }
</script>

<style scoped>

</style>
